"use strict";

import axios from "axios";

const AUTH_TOKEN = "Basic dXNlcjoxMjM0NTY=";
const WEB_TOKEN = '4afe00e331319764a2b019b22d07191c215133d718bd770ef5033b9f7b0f247c';

// Full config:  https://github.com/axios/axios#request-config
// axios.defaults.baseURL = process.env.baseURL || process.env.apiUrl || '';

axios.defaults.headers.post['Authorization'] = AUTH_TOKEN;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
axios.defaults.headers.post['webToken'] = WEB_TOKEN;

let config = {
  // baseURL: "",
  baseURL: "http://dev.user.ihongyin.com",
  timeout: 60 * 1000, // Timeout
  // withCredentials: true, // Check cross-site Access-Control
};

const _axios = axios.create(config);

_axios.interceptors.request.use(
  function(config) {
    // Do something before request is sent
    return config;
  },
  function(error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

// Add a response interceptor
_axios.interceptors.response.use(
  function(response) {
    // Do something with response data
    return response;
  },
  function(error) {
    // Do something with response error
    return Promise.reject(error);
  }
);

// eslint-disable-next-line no-unused-vars
Plugin.install = function(Vue, options) {
  Vue.prototype.$axios = _axios;
  window.axios = _axios;
};

export default Plugin;
